<?php

/**
 * Created by PhpStorm.
 * User: wukent
 * Date: 2017/9/26
 * Time: 上午11:19
 */
class OfflineOrderModel extends Model
{

    public function entry($uid,$total_money,$ordertime) {
        $edata['order_sn'] = $total_money;
        $edata['merchant_id'] = I('post.merchant_id');
        $edata['user_id'] = $uid;
        $edata['total_money'] = I('post.total_money');
        $edata['actual_money'] = I('post.actual_money');
        $edata['actual_points'] = I('post.actual_points');
        $edata['pay_type'] = I('post.pay_type');
        $edata['datetime'] = $ordertime;
        $edata['status'] = 0;
        $data = $this->add($edata);

        return $data;
    }


    public function upstatus($out_trade_no,$status) {
        $edata['status'] = $status;
        $where = array('order_sn'=>$out_trade_no);
        $data = $this->where($where)->save($edata);
        return $data;
    }

    public function getInfo($order_sn) {
        $where = array('order_sn'=>$order_sn);
        $data = $this->where($where)->find();
        return $data;
    }

    public function numList($uid,$page="1",$pernum="5") {

        $where = array('user_id'=>$uid,'status'=>1);
        $data = $this
            ->join(C('DB_PREFIX').'merchant ON '.C('DB_PREFIX').'merchant.merchant_id = '.C('DB_PREFIX').'offline_order.merchant_id')
            ->where($where)
            ->order('datetime DESC')
            ->page($page.','.$pernum)
            ->select();


        return $data;

    }

}